package aptech.eproject.logictics.db;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.util.Set;

/**
 * The persistent class for the DELIVERY database table.
 * 
 */
@Entity
@Table(name = "DELIVERY")
@NamedQueries({
    @NamedQuery(name = "findAllDeliveries", query = "SELECT d FROM Delivery d WHERE d.isDeleted = 'FALSE'"),
    @NamedQuery(name = "findDeliveries", query = "SELECT d FROM Delivery d WHERE d.isDeleted = 'FALSE' AND d.startBranch.branchId = ?1"),
    @NamedQuery(name = "findDelivery", query = "SELECT d FROM Delivery d WHERE d.isDeleted = 'FALSE' AND d.startBranch.branchId = ?1 AND d.deliveryId = ?2"),
    @NamedQuery(name = "findDeliveryByTrackingCode", query = "SELECT d FROM Delivery d WHERE d.isDeleted = 'FALSE' AND d.trackingCode = ?1"),
    @NamedQuery(name = "findDeliveriesByBookingStatus", query = "SELECT d FROM Delivery d WHERE d.isDeleted = 'FALSE' AND d.bookingStatus = ?1")
})
public class Delivery implements Serializable {

    private static final long serialVersionUID = 1L;
    private int deliveryId;
    private Timestamp bookedDate;
    private BookingStatus bookingStatus;
    private BigDecimal comission;
    private Timestamp confirmedDate;
    private String consigneeAddress;
    private String consigneeName;
    private String customerccNumber;
    private Timestamp deliveryDate;
    private boolean isDeleted;
    private boolean isFinished;
    private String pickUpAddress;
    private Timestamp pickupDate;
    private BigDecimal pubnishRate;
    private BigDecimal rate;
    private double totalWeight;
    private String trackingCode;
    private Branch destinationBranch;
    private Branch startBranch;
    private Customer consigner;
    private Set<Package> packages;

    public Delivery() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "DELIVERY_ID")
    public int getDeliveryId() {
        return this.deliveryId;
    }

    public void setDeliveryId(int deliveryId) {
        this.deliveryId = deliveryId;
    }

    @Column(name = "BOOKED_DATE", nullable = true)
    public Timestamp getBookedDate() {
        return this.bookedDate;
    }

    public void setBookedDate(Timestamp bookedDate) {
        this.bookedDate = bookedDate;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "BOOKING_STATUS", nullable = true)
    public BookingStatus getBookingStatus() {
        return bookingStatus;
    }

    public void setBookingStatus(BookingStatus bookingStatus) {
        this.bookingStatus = bookingStatus;
    }

    @Column(name = "COMISSION", nullable = true)
    public BigDecimal getComission() {
        return this.comission;
    }

    public void setComission(BigDecimal comission) {
        this.comission = comission;
    }

    @Column(name = "CONFIRMED_DATE", nullable = true)
    public Timestamp getConfirmedDate() {
        return this.confirmedDate;
    }

    public void setConfirmedDate(Timestamp confirmedDate) {
        this.confirmedDate = confirmedDate;

    }

    @Column(name = "CONSIGNEE_ADDRESS", nullable = false)
    public String getConsigneeAddress() {
        return this.consigneeAddress;
    }

    public void setConsigneeAddress(String consigneeAddress) {
        this.consigneeAddress = consigneeAddress;
    }

    @Column(name = "CONSIGNEE_NAME", nullable = false)
    public String getConsigneeName() {
        return this.consigneeName;
    }

    public void setConsigneeName(String consigneeName) {
        this.consigneeName = consigneeName;
    }

    @Column(name = "CUSTOMERCC_NUMBER", nullable = true)
    public String getCustomerccNumber() {
        return this.customerccNumber;
    }

    public void setCustomerccNumber(String customerccNumber) {
        this.customerccNumber = customerccNumber;
    }

    @Column(name = "DELIVERY_DATE", nullable = true)
    public Timestamp getDeliveryDate() {
        return this.deliveryDate;
    }

    public void setDeliveryDate(Timestamp deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    @Column(name = "IS_DELETED", nullable = true)
    public boolean getIsDeleted() {
        return this.isDeleted;
    }

    public void setIsDeleted(boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    @Column(name = "IS_FINISHED", nullable = true)
    public boolean getIsFinished() {
        return this.isFinished;
    }

    public void setIsFinished(boolean isFinished) {
        this.isFinished = isFinished;
    }

    @Column(name = "PICK_UP_ADDRESS", nullable = true)
    public String getPickUpAddress() {
        return this.pickUpAddress;
    }

    public void setPickUpAddress(String pickUpAddress) {
        this.pickUpAddress = pickUpAddress;
    }

    @Column(name = "PICKUP_DATE", nullable = false)
    public Timestamp getPickupDate() {
        return this.pickupDate;
    }

    public void setPickupDate(Timestamp pickupDate) {
        this.pickupDate = pickupDate;
    }

    @Column(name = "PUBNISH_RATE", nullable = true)
    public BigDecimal getPubnishRate() {
        return this.pubnishRate;
    }

    public void setPubnishRate(BigDecimal pubnishRate) {
        this.pubnishRate = pubnishRate;
    }

    @Column(name = "RATE", nullable = true)
    public BigDecimal getRate() {
        return this.rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    @Column(name = "TOTAL_WEIGHT", nullable = false)
    public double getTotalWeight() {
        return this.totalWeight;
    }

    public void setTotalWeight(double totalWeight) {
        this.totalWeight = totalWeight;
    }

    @Column(name = "TRACKING_CODE", nullable = true)
    public String getTrackingCode() {
        return this.trackingCode;
    }

    public void setTrackingCode(String trackingCode) {
        this.trackingCode = trackingCode;
    }

    //bi-directional many-to-one association to Branch
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "DESTINATION_BRANCH_ID", nullable = false)
    public Branch getDestinationBranch() {
        return this.destinationBranch;
    }

    public void setDestinationBranch(Branch destinationBranch) {
        this.destinationBranch = destinationBranch;
    }

    //bi-directional many-to-one association to Branch
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "START_BRANCH_ID", nullable = false)
    public Branch getStartBranch() {
        return this.startBranch;
    }

    public void setStartBranch(Branch startBranch) {
        this.startBranch = startBranch;
    }

    //bi-directional many-to-one association to Customer
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "CONSIGNER_ID", nullable = false)
    public Customer getConsigner() {
        return consigner;
    }

    public void setConsigner(Customer consigner) {
        this.consigner = consigner;
    }

    //bi-directional many-to-one association to Package
    @OneToMany(mappedBy = "delivery", fetch = FetchType.EAGER)
    public Set<Package> getPackages() {
        return this.packages;
    }

    public void setPackages(Set<Package> packages) {
        this.packages = packages;
    }

    public Package addPackage(Package pack) {
        getPackages().add(pack);
        return pack;
    }

    public Package removePackage(Package pack) {
        getPackages().remove(pack);
        pack.setDelivery(null);
        return pack;
    }
}
